package com.kmproject.haifu.mvp.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.integration.AppManager;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.DataHelper;
import com.jess.arms.widget.CustomPopupWindow;
import com.jess.arms.widget.alertview.AlertView;
import com.jess.arms.widget.alertview.AlertViewOnItemClickListener;
import com.jess.arms.widget.autolayout.AutoToolbar;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.AppConstant;
import com.kmproject.haifu.app.AppInfoAplication;
import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.app.utils.Glide4Engine;
import com.kmproject.haifu.di.component.DaggerMyStoryAddStoryComponent;
import com.kmproject.haifu.mvp.contract.MyStoryAddStoryContract;
import com.kmproject.haifu.mvp.model.api.Api;
import com.kmproject.haifu.mvp.model.entity.MessageEvent;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.model.entity.beans.MyStoreMainBean;
import com.kmproject.haifu.mvp.model.entity.beans.MyStoryBean;
import com.kmproject.haifu.mvp.model.entity.beans.UserBean;
import com.kmproject.haifu.mvp.model.entity.resbean.SelectAddressMapBean;
import com.kmproject.haifu.mvp.model.entity.resbean.StoreAddParmarBean;
import com.kmproject.haifu.mvp.model.entity.resbean.StoryImageType;
import com.kmproject.haifu.mvp.presenter.MyStoryAddStoryPresenter;
import com.kmproject.haifu.mvp.ui.widget.MultiSelectPopWindow1;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.internal.entity.CaptureStrategy;

import java.io.File;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import top.zibin.luban.CompressionPredicate;
import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 07/29/2019 14:40
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class MyStoryAddStoryActivity extends BaseActivity<MyStoryAddStoryPresenter> implements MyStoryAddStoryContract.View {

    @BindView(R.id.toolbar_backImg)
    ImageView toolbarBackImg;
    @BindView(R.id.toolbar_back)
    RelativeLayout toolbarBack;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.back_right_icon)
    ImageView backRightIcon;
    @BindView(R.id.back_right_txt)
    TextView backRightTxt;
    @BindView(R.id.toolbar_right)
    RelativeLayout toolbarRight;
    @BindView(R.id.toolbar)
    AutoToolbar toolbar;
    @BindView(R.id.Mystory_addStory_dpmc)
    EditText MystoryAddStoryDpmc;
    @BindView(R.id.Mystory_addStory_lxdh)
    EditText MystoryAddStoryLxdh;
    @BindView(R.id.Mystory_addStory_szqy)
    TextView MystoryAddStorySzqy;
    @BindView(R.id.Mystory_addStory_xxdz)
    EditText MystoryAddStoryXxdz;
    @BindView(R.id.Mystory_addStory_dpLogo)
    ImageView MystoryAddStoryDpLogo;
    @BindView(R.id.Mystory_addStory_frxm)
    EditText MystoryAddStoryFrxm;
    @BindView(R.id.Mystory_addStory_sfz)
    TextView MystoryAddStorySfz;
    @BindView(R.id.Mystory_addStory_yyzz)
    TextView MystoryAddStoryYyzz;
    @BindView(R.id.Mystory_addStory_descript)
    EditText MystoryAddStoryDescript;
    @BindView(R.id.Mystory_addStory_txt_num)
    TextView MystoryAddStoryTxtNum;
    @BindView(R.id.mystore_selectstory_popuwindow_add_txt)
    TextView mystoreSelectstoryPopuwindowAddTxt;
    @BindView(R.id.Mystory_addStory_PhoneSsqy_txt)
    TextView MystoryAddStoryPhoneSsqyTxt;
    @BindView(R.id.Mystory_addStory_dplx)
    TextView MystoryAddStoryDplx;
    @BindView(R.id.Mystory_addStory_dplx_lay)
    LinearLayout MystoryAddStoryDplxLay;
    @BindView(R.id.Mystory_addStory_dplx_line)
    View MystoryAddStoryDplxLine;
    @BindView(R.id.Mystory_addStory_dpLogo_cxsc_txt)
    TextView MystoryAddStoryDpLogoCxscTxt;
    @BindView(R.id.Mystory_addStory_dpLogo_cxsc_lay)
    LinearLayout MystoryAddStoryDpLogoCxscLay;
    @BindView(R.id.Mystory_addStory_frxx_layout)
    LinearLayout MystoryAddStoryFrxxLayout;
    private List<HousePayWayBean> houseArea;//区域
    RxPermissions mRxPermissions;
    private HousePayWayBean dpType;//用户选中的店铺
    private StoryImageType selectImgType;//选择图片类型storeLogo,businessLicense, idCardFront,idCardReverseSide,passport;
    private StoreAddParmarBean storeAddParmarBean = new StoreAddParmarBean();

    private MyStoreMainBean myStoreMainBean;//从我的店铺主页跳转过来的编辑
    int roomIndex =-1;
    int drawIndex =-1;
    int toilteIndex = -1;
    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerMyStoryAddStoryComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_my_story_add_story; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
//        MystoryAddStoryXxdz.setText("测试地址");
//        storeAddParmarBean.setLat("25.2323");
//        storeAddParmarBean.setLgt("102.3434");
//        storeAddParmarBean.setAddressDetail("测试时十四hi地址");

        if (getIntent().hasExtra("MyStoreMainBean")) {
            myStoreMainBean = (MyStoreMainBean) getIntent().getSerializableExtra("MyStoreMainBean");
            if (myStoreMainBean.getBusinessLicense() != null && !TextUtils.isEmpty(myStoreMainBean.getBusinessLicense())) {
                getMystoryAddStoryYyzz().setText(ArmsUtils.getString(this, R.string.housepublishpublish_yxz));
            }

            if (myStoreMainBean.getIdCardFront() != null && !TextUtils.isEmpty(myStoreMainBean.getIdCardFront())
                    && myStoreMainBean.getIdCardReverseSide() != null && !TextUtils.isEmpty(myStoreMainBean.getIdCardReverseSide())) {
                getMystoryAddStorySfz().setText(ArmsUtils.getString(this, R.string.housepublishpublish_yxz));
            }
            if (myStoreMainBean.getPassport() != null && !TextUtils.isEmpty(myStoreMainBean.getPassport())) {
                getMystoryAddStorySfz().setText(ArmsUtils.getString(this, R.string.housepublishpublish_yxz));
            }
            storeAddParmarBean.setAddressDetail(myStoreMainBean.getAddressDetail());
            storeAddParmarBean.setBusinessLicense(myStoreMainBean.getBusinessLicense());
            storeAddParmarBean.setIdCardFront(myStoreMainBean.getIdCardFront());
            storeAddParmarBean.setIdCardReverseSide(myStoreMainBean.getIdCardReverseSide());
            storeAddParmarBean.setLat(myStoreMainBean.getLat());
            storeAddParmarBean.setLegalPersonName(myStoreMainBean.getLegalPersonName());
            storeAddParmarBean.setLgt(myStoreMainBean.getLgt());
            storeAddParmarBean.setPassport(myStoreMainBean.getPassport());
            storeAddParmarBean.setStoreArea(myStoreMainBean.getStoreArea());
            storeAddParmarBean.setStoreDetail(myStoreMainBean.getStoreDetail());
            storeAddParmarBean.setStoreLogo(myStoreMainBean.getStoreLogo());
            storeAddParmarBean.setStoreMobile(myStoreMainBean.getStoreMobile().substring(2,myStoreMainBean.getStoreMobile().length()));
            storeAddParmarBean.setStoreName(myStoreMainBean.getStoreName());
            storeAddParmarBean.setStoreType(myStoreMainBean.getStoreType());

            MystoryAddStoryDplxLay.setVisibility(View.VISIBLE);
            MystoryAddStoryDplxLine.setVisibility(View.VISIBLE);
            MystoryAddStoryDplx.setText(myStoreMainBean.getStoreTypeName());
            MystoryAddStoryDplx.setEnabled(false);
            MystoryAddStoryDpmc.setText(myStoreMainBean.getStoreName());
            MystoryAddStoryDpmc.setEnabled(false);
            if (myStoreMainBean.getStoreDetail()!=null&&!TextUtils.isEmpty(myStoreMainBean.getStoreDetail()))
            {
                MystoryAddStoryTxtNum.setText(myStoreMainBean.getStoreDetail().length() + "/500");
            }

            MystoryAddStoryLxdh.setText(storeAddParmarBean.getStoreMobile());
            if (storeAddParmarBean.getStoreMobile().length()>1&&"1".equals(storeAddParmarBean.getStoreMobile().substring(0,1)))
            {
                MystoryAddStoryPhoneSsqyTxt.setText("+86");
            }else {
                MystoryAddStoryPhoneSsqyTxt.setText("+63");
            }
            MystoryAddStorySzqy.setText((myStoreMainBean.getStoreAreaName() != null && myStoreMainBean.getStoreAreaName().size() > 0) ? myStoreMainBean.getStoreAreaName().get(0).getName() : "");
            MystoryAddStoryXxdz.setText(myStoreMainBean.getAddressDetail());
            MystoryAddStoryDescript.setText(myStoreMainBean.getStoreDetail());

            MystoryAddStoryDplx.setTextColor(ArmsUtils.getColor(this,R.color.color_999999));
            MystoryAddStoryDpmc.setTextColor(ArmsUtils.getColor(this,R.color.color_999999));
            MystoryAddStoryLxdh.setTextColor(ArmsUtils.getColor(this,R.color.color_191919));
            MystoryAddStorySzqy.setTextColor(ArmsUtils.getColor(this,R.color.color_191919));
            MystoryAddStoryXxdz.setTextColor(ArmsUtils.getColor(this,R.color.color_191919));
            MystoryAddStoryDescript.setTextColor(ArmsUtils.getColor(this,R.color.color_999999));
            if (myStoreMainBean.getLogoUpdateCount() < 1) {
                //log修改次数小于1时候才显示修改
                MystoryAddStoryDpLogoCxscLay.setVisibility(View.VISIBLE);
            } else {
                MystoryAddStoryDpLogo.setEnabled(false);//不允许修改
            }
            MystoryAddStoryFrxm.setText(myStoreMainBean.getLegalPersonName());
           //法人姓名不可编辑
            MystoryAddStoryFrxm.setFocusable(false);
            MystoryAddStoryFrxm.setFocusableInTouchMode(false);
              if ((myStoreMainBean.getPassport() == null || TextUtils.isEmpty(myStoreMainBean.getPassport())) && ((myStoreMainBean.getIdCardReverseSide() == null || TextUtils.isEmpty(myStoreMainBean.getIdCardReverseSide())) || (myStoreMainBean.getIdCardFront() == null || TextUtils.isEmpty(myStoreMainBean.getIdCardFront())))) {
                  MystoryAddStorySfz.setText(ArmsUtils.getString(this,R.string.housepublishpublish_wsc));
                }else {
                  MystoryAddStorySfz.setText(ArmsUtils.getString(this,R.string.housepublishpublish_ysc));
              }
                //营业执照
                if (myStoreMainBean.getBusinessLicense() == null || TextUtils.isEmpty(myStoreMainBean.getBusinessLicense())) {
                    MystoryAddStoryYyzz.setText(ArmsUtils.getString(this,R.string.housepublishpublish_wsc));
                }else {
                    MystoryAddStoryYyzz.setText(ArmsUtils.getString(this,R.string.housepublishpublish_ysc));
                }


            MystoryAddStorySfz.setTextColor(ArmsUtils.getColor(this,R.color.color_191919));
            MystoryAddStoryYyzz.setTextColor(ArmsUtils.getColor(this,R.color.color_191919));
            MystoryAddStoryDescript.setTextColor(ArmsUtils.getColor(this,R.color.color_191919));
            getMglideImage().loadImage(this, ImageConfigImpl.builder().url(myStoreMainBean.getStoreLogo())
                    .imageView(MystoryAddStoryDpLogo)
                    .build());
            mystoreSelectstoryPopuwindowAddTxt.setText(ArmsUtils.getString(this,R.string.mystory_bc));
        }else {
            MystoryAddStoryXxdz.setFocusable(false);
            UserBean userBean= DataHelper.getDeviceData(this,AppConstant.USER_INFO);
            if(userBean!=null&&userBean.getMobile()!=null&&userBean.getMobile().length()>2)
            {
                MystoryAddStoryLxdh.setText(userBean.getMobile().substring(2,userBean.getMobile().length()));
            }
        }
        if (MystoryAddStoryLxdh.getText().toString().length()>1&&"1".equals(MystoryAddStoryLxdh.getText().toString().substring(0,1)))
        {
            MystoryAddStoryPhoneSsqyTxt.setText("+86");
        }else {
            MystoryAddStoryPhoneSsqyTxt.setText("+63");
        }
        toolbarTitle.setText(ArmsUtils.getString(this, R.string.mystory_add_xzdp));
        toolbarTitle.setTextColor(ArmsUtils.getColor(this, R.color.white));
        toolbar.setBackgroundColor(ArmsUtils.getColor(this, R.color.color_3F3F4B));
        toolbarBackImg.setImageResource(R.drawable.member_center_main_back_img);
        mystoreSelectstoryPopuwindowAddTxt.setBackgroundResource(R.drawable.button_yellow_bg);
        mystoreSelectstoryPopuwindowAddTxt.setTextColor(ArmsUtils.getColor(MyStoryAddStoryActivity.this, R.color.color_191919));

        mRxPermissions = new RxPermissions(this);
        if (!getIntent().hasExtra("MyStoreMainBean")) {
            mPresenter.dictList();
        }

        MystoryAddStoryDescript.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s != null) {
                    MystoryAddStoryTxtNum.setText(s.length() + "/500");
                }
                if (s.length() > 1) {
                    mystoreSelectstoryPopuwindowAddTxt.setBackgroundResource(R.drawable.button_yellow_bg);
                    mystoreSelectstoryPopuwindowAddTxt.setTextColor(ArmsUtils.getColor(MyStoryAddStoryActivity.this, R.color.color_191919));
                } else {
                    mystoreSelectstoryPopuwindowAddTxt.setBackgroundResource(R.drawable.button_gray_bg);
                    mystoreSelectstoryPopuwindowAddTxt.setTextColor(ArmsUtils.getColor(MyStoryAddStoryActivity.this, R.color.white));

                }
            }
        });
    }


    @Override
    public String reSetTitle() {
        return getIntent().hasExtra("MyStoreMainBean") ? ArmsUtils.getString(this, R.string.hf_me_dpgl) : ArmsUtils.getString(this, R.string.mystory_add_xzdp);
    }

    @Override
    public void showLoading() {
        loadingDialog.show();
    }

    @Override
    public void hideLoading() {
        loadingDialog.dismiss();
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.Mystory_addStory_xxdz_lay,R.id.Mystory_addStory_dpLogo_cxsc_txt, R.id.Mystory_addStory_PhoneSsqy_txt, R.id.Mystory_addStory_szqy, R.id.Mystory_addStory_xxdz, R.id.Mystory_addStory_dpLogo, R.id.Mystory_addStory_sfz, R.id.Mystory_addStory_yyzz, R.id.mystore_selectstory_popuwindow_add_txt})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.Mystory_addStory_szqy:
                //所在区域
                mPresenter.getHouseArea(Api.HOUSE_AREA, houseArea);
                break;
            case R.id.Mystory_addStory_xxdz_lay:
                if (houseArea==null||roomIndex<0||drawIndex<0)
                {
                    showMessage("请选择区域");
                    return;
                }

                //具体地址
                Intent intentMap1 = new Intent(this, MapSelectAddressActivity.class);
                intentMap1.putExtra("selectedAreaName", houseArea.get(roomIndex).getChildren().get(drawIndex).getName());
                intentMap1.putExtra("lat",houseArea.get(roomIndex).getChildren().get(drawIndex).getLat());
                intentMap1.putExtra("lng",houseArea.get(roomIndex).getChildren().get(drawIndex).getLgt());
                startActivityForResult(intentMap1, 1004);
                break;
            case R.id.Mystory_addStory_xxdz:
                if (storeAddParmarBean.getLat()!=null&&storeAddParmarBean.getLgt()!=null&&!TextUtils.isEmpty(storeAddParmarBean.getLat())&&!TextUtils.isEmpty(storeAddParmarBean.getLgt()))
                {
                    return;
                }
                //具体地址
                Intent intentMap = new Intent(this, MapSelectAddressActivity.class);
                intentMap.putExtra("selectedAreaName", MystoryAddStorySzqy.getText().toString());
                startActivityForResult(intentMap, 1004);
                break;
            case R.id.Mystory_addStory_dpLogo:
                selectImgType = StoryImageType.storeLogo;
                mPresenter.requestPrisession();
                break;
            case R.id.Mystory_addStory_sfz:
                mPresenter.showPopuWindowToSFZ(this, MystoryAddStorySfz);

                break;
            case R.id.Mystory_addStory_yyzz:
                mPresenter.showPopuWindowToYYZZ(this, MystoryAddStoryYyzz);
                break;
            case R.id.mystore_selectstory_popuwindow_add_txt:
                if (MystoryAddStoryPhoneSsqyTxt.getText().toString().contains("63"))
                {
                    if (MystoryAddStoryLxdh.getText().toString().trim().length()!=10)
                    {
                        showMessage("号码长度有误，请填写正确的号码");
                        return;
                    }
                }else {
                    if (MystoryAddStoryLxdh.getText().toString().trim().length()!=11)
                    {
                        showMessage("号码长度有误，请填写正确的号码");
                        return;
                    }
                }

                if (getIntent().hasExtra("MyStoreMainBean")) {
                    //编辑信息
                    if (TextUtils.isEmpty(MystoryAddStoryDpmc.getText().toString()) || MystoryAddStoryDpmc.getText().toString().length() < 1) {
                        showMessage("请输入店铺名称");
                        return;
                    }
                    if (TextUtils.isEmpty(MystoryAddStoryLxdh.getText().toString()) || MystoryAddStoryLxdh.getText().toString().length() < 1) {
                        showMessage("请输入联系电话");
                        return;
                    }
                    if (MystoryAddStoryPhoneSsqyTxt.getText().toString().equals("+63"))
                    {
                        if (MystoryAddStoryLxdh.getText().toString().substring(0,1).equals("0"))
                        {
                            showMessage("手机号不能是0开头");
                            return;
                        }
                        if (!MystoryAddStoryLxdh.getText().toString().substring(0,1).equals("9"))
                        {
                            showMessage("手机号必须是9开头");
                            return;
                        }
                        if (MystoryAddStoryLxdh.getText().toString().length()!=10)
                        {
                            showMessage("手机号长度必须是十位");
                            return;
                        }
                    }else {
                        if (MystoryAddStoryLxdh.getText().toString().length()!=11)
                        {
                            showMessage("手机号必须是11位");
                            return;
                        }

                    }


                    if (storeAddParmarBean.getStoreArea() == null || TextUtils.isEmpty(storeAddParmarBean.getStoreArea())) {
                        showMessage("请选择区域");
                        return;
                    }
                    if (TextUtils.isEmpty(MystoryAddStoryXxdz.getText().toString()) || MystoryAddStoryXxdz.getText().toString().length() < 1) {
                        showMessage("请选择详细地址");
                        return;
                    }

                    storeAddParmarBean.setAddressDetail(MystoryAddStoryXxdz.getText().toString());
                    storeAddParmarBean.setStoreName(MystoryAddStoryDpmc.getText().toString());
                    storeAddParmarBean.setStoreMobile( (MystoryAddStoryPhoneSsqyTxt.getText().toString().contains("63")?"63":"86")+MystoryAddStoryLxdh.getText().toString());
                    storeAddParmarBean.setStoreDetail(MystoryAddStoryDescript.getText().toString());
                    mPresenter.updateStore(myStoreMainBean.getStoreId(),storeAddParmarBean);
                    return;
                }

                //测试把地址写死
//                MystoryAddStoryXxdz.setText("测试地址");
//                storeAddParmarBean.setLat("25.45656");
//                storeAddParmarBean.setLgt("102.45645");
//                storeAddParmarBean.setAddressDetail("测试详细地址");


                if (TextUtils.isEmpty(MystoryAddStoryDpmc.getText().toString()) || MystoryAddStoryDpmc.getText().toString().length() < 1) {
                    showMessage("请输入店铺名称");
                    return;
                }
                if (TextUtils.isEmpty(MystoryAddStoryLxdh.getText().toString()) || MystoryAddStoryLxdh.getText().toString().length() < 1) {
                    showMessage("请输入联系电话");
                    return;
                }
                if (storeAddParmarBean.getStoreArea() == null || TextUtils.isEmpty(storeAddParmarBean.getStoreArea())) {
                    showMessage("请选择区域");
                    return;
                }
                if (TextUtils.isEmpty(MystoryAddStoryXxdz.getText().toString()) || MystoryAddStoryXxdz.getText().toString().length() < 1) {
                    showMessage("请选择详细地址");
                    return;
                }
                if (storeAddParmarBean.getStoreLogo() == null || TextUtils.isEmpty(storeAddParmarBean.getStoreLogo())) {
                    showMessage("请选择店铺LOGO");
                    return;
                }
                if (TextUtils.isEmpty(MystoryAddStoryFrxm.getText().toString()) || MystoryAddStoryFrxm.getText().toString().length() < 1) {
                    showMessage("请输入店铺法人姓名");
                    return;
                }
//                if ((storeAddParmarBean.getPassport() == null || TextUtils.isEmpty(storeAddParmarBean.getPassport())) && ((storeAddParmarBean.getIdCardReverseSide() == null || TextUtils.isEmpty(storeAddParmarBean.getIdCardReverseSide())) || (storeAddParmarBean.getIdCardFront() == null || TextUtils.isEmpty(storeAddParmarBean.getIdCardFront())))) {
//                    showMessage("请选择选择身份证或护照");
//                    return;
//                }
//                //营业执照
//                if (storeAddParmarBean.getBusinessLicense() == null || TextUtils.isEmpty(storeAddParmarBean.getBusinessLicense())) {
//                    showMessage("请选择营业执照");
//                    return;
//                }
//                if (TextUtils.isEmpty(MystoryAddStoryDescript.getText().toString())) {
//                    showMessage("请输入店铺描述信息");
//                    return;
//                }
                storeAddParmarBean.setStoreName(MystoryAddStoryDpmc.getText().toString());
                storeAddParmarBean.setStoreMobile(MystoryAddStoryPhoneSsqyTxt.getText().toString().replace("+", "").trim() + MystoryAddStoryLxdh.getText().toString());
                storeAddParmarBean.setLegalPersonName(MystoryAddStoryFrxm.getText().toString());
                storeAddParmarBean.setStoreDetail(MystoryAddStoryDescript.getText().toString());
                mPresenter.addStore(storeAddParmarBean);
                break;
            case R.id.Mystory_addStory_PhoneSsqy_txt:
                showPopuWindow();
                break;
            case R.id.Mystory_addStory_dpLogo_cxsc_txt:
                selectImgType = StoryImageType.storeLogo;
                mPresenter.requestPrisession();
                break;
        }
    }

    @Override
    public void requestPerimissionSuccess() {
        //拍照界面
        Matisse.from(this)
                .choose(MimeType.ofImage())
                .countable(true)
                .capture(true)
                .captureStrategy(
//                new CaptureStrategy(true, "com.lxc.inspectionmanagement.fileprovider"))
                        new CaptureStrategy(true, "com.kmproject.haifu.fileprovider"))
                .maxSelectable(1)
                .gridExpectedSize(getResources().getDimensionPixelSize(R.dimen.grid_expected_size))
                .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
                .thumbnailScale(0.85f)
                .imageEngine(new Glide4Engine())
                .forResult(AppConstant.REQUEST_CODE_CHOOSE);
    }

    @Override
    public RxPermissions getPermissions() {
        return mRxPermissions;
    }

    @Override
    public void getHouseArea(List<HousePayWayBean> housePayWayBeans) {
        this.houseArea = housePayWayBeans;
        new MultiSelectPopWindow1.Builder(this)
                .setConfirmListener(new MultiSelectPopWindow1.OnConfirmClickListener() {
                    @Override
                    public void onClick(MessageEvent messageEvent) {
                        //所在区域
                        MystoryAddStorySzqy.setText(messageEvent.getRoom() + (messageEvent.getDrawing() != null ? messageEvent.getDrawing() : "") + (messageEvent.getToilet() != null ? messageEvent.getToilet() : ""));
                         roomIndex = messageEvent.getRoomIndex();
                         drawIndex = messageEvent.getDrawingIndex();
                         toilteIndex = messageEvent.getToiletIndex();
                        String temArea = "";
                        if (roomIndex < 0) {
                            showMessage("请选择区域");
                            return;
                        }
                        temArea = houseArea.get(roomIndex).getDictId();
                        if (drawIndex > 0) {
                            temArea = houseArea.get(roomIndex).getChildren().get(drawIndex).getDictId();
                        }
                        if (drawIndex > 0 && toilteIndex > 0) {
                            temArea = houseArea.get(roomIndex).getChildren().get(drawIndex).getChildren().get(toilteIndex).getDictId();
                        }
                        storeAddParmarBean.setStoreArea(temArea);
                    }
                })
                .setDataArray(housePayWayBeans)
                .setCancel(ArmsUtils.getString(this, R.string.user_set_editinfo_cancel))
                .setTitle(ArmsUtils.getString(this, R.string.dilaog_titile_xzszqy_txt))
                .setConfirm(ArmsUtils.getString(this, R.string.sure_txt))
                .build()
                .show(MystoryAddStorySzqy);
    }

    @Override
    public void updateImgSuccess(StoryImageType type, String servicePath) {
        //storeLogo,businessLicense, idCardFront,idCardReverseSide,passport;
        if (StoryImageType.storeLogo.equals(type)) {
            //店铺logo
            storeAddParmarBean.setStoreLogo(servicePath);
            MystoryAddStoryDpLogo.postDelayed(new Runnable() {
                @Override
                public void run() {
                    getMglideImage().loadImage(MyStoryAddStoryActivity.this, ImageConfigImpl.builder().url(servicePath)
                            .imageView(MystoryAddStoryDpLogo)
                            .build());
                }
            }, 1000);

            showMessage(ArmsUtils.getString(this, R.string.mystory_dplogo_success));
        } else if (StoryImageType.businessLicense.equals(type)) {
            // 营业执照
            storeAddParmarBean.setBusinessLicense(servicePath);
            showMessage(ArmsUtils.getString(this, R.string.mystory_yyzz_success));
        } else if (StoryImageType.idCardFront.equals(type)) {
            showMessage(ArmsUtils.getString(this, R.string.mystory_sfzzm_success));
        } else if (StoryImageType.passport.equals(type)) {
            showMessage(ArmsUtils.getString(this, R.string.mystory_hz_success));
        } else if (StoryImageType.idCardReverseSide.equals(type)) {
            showMessage(ArmsUtils.getString(this, R.string.mystory_sfzbm_success));
        }
    }

    @Override
    public void dictListSuccess(List<HousePayWayBean> housePayWayBeans) {
        mPresenter.showPopuWindowToXZDPType(this, MystoryAddStoryPhoneSsqyTxt, housePayWayBeans, new MyStoryAddStoryPresenter.ItemClick() {
            @Override
            public void callBack(int index, HousePayWayBean housePayWayBean) {
                dpType = housePayWayBean;
                storeAddParmarBean.setStoreType(housePayWayBean.getDictId());
            }
        });
    }

    @Override
    public StoreAddParmarBean getStoreAddParmarBean() {
        return storeAddParmarBean;
    }

    @Override
    public ImageLoader getGlideImg() {
        return getMglideImage();
    }

    @Override
    public Activity getStoryActivity() {
        return this;
    }

    /**
     * 控制popu显示
     */
    public void showPopuWindow() {
        CustomPopupWindow customPopupWindow = new CustomPopupWindow.Builder().contentView(CustomPopupWindow.inflateView(this, R.layout.user_popuwindow_view)).parentView(MystoryAddStoryPhoneSsqyTxt).backgroundDrawable(getResources().getDrawable(R.drawable.button_white_bg))
                .animationStyle(R.style.mypopwindow_anim_style).customListener(new CustomPopupWindow.CustomPopupWindowListener() {
                    @Override
                    public void initPopupView(View contentView) {

                    }
                }).isWrap(true).isHaveBackGround(true).build();
        View view1 = customPopupWindow.getContentView();
        TextView user_popuwindow_view_flb = view1.findViewById(R.id.user_popuwindow_view_flb);
        TextView user_popuwindow_view_zg = view1.findViewById(R.id.user_popuwindow_view_zg);
        user_popuwindow_view_flb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MystoryAddStoryPhoneSsqyTxt.setText("+63");
                customPopupWindow.dismiss();
            }
        });
        user_popuwindow_view_zg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MystoryAddStoryPhoneSsqyTxt.setText("+86");
                customPopupWindow.dismiss();
            }
        });
        customPopupWindow.show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null && requestCode == AppConstant.REQUEST_CODE_CHOOSE) {
            List<Uri> mSelected = Matisse.obtainResult(data);
            if (mSelected != null && !mSelected.isEmpty()) {
                AppUtil.getBitmapFromUri(this, mSelected.get(0));
            }
            Log.d("Matisse", "mSelected: " + mSelected);
            if (!mSelected.isEmpty()) {

                String path = AppUtil.getFromMediaUri(this, getContentResolver(), mSelected.get(0));
                if (!TextUtils.isEmpty(path)) {
                    File file = new File(path);
                    if (file != null && file.exists()) {
                        Luban.with(this)
                                .load(file)
                                .ignoreBy(100)
                                //                                .setTargetDir()
                                .filter(new CompressionPredicate() {
                                    @Override
                                    public boolean apply(String path) {
                                        return !(TextUtils.isEmpty(path) || path.toLowerCase().endsWith(".gif"));
                                    }
                                })
                                .setCompressListener(new OnCompressListener() {
                                    @Override
                                    public void onStart() {
                                        // TODO 压缩开始前调用，可以在方法内启动 loading UI
                                    }

                                    @Override
                                    public void onSuccess(File file) {

                                        //上传图片
                                        mPresenter.updateHeadImg(selectImgType, file);
//                                        creatPublishNongHuHolder.addpath(file.getPath());
                                    }

                                    @Override
                                    public void onError(Throwable e) {
                                        // TODO 当压缩过程出现问题时调用
                                    }
                                }).launch();
                    }
                }

            }
        } else if (requestCode == 1004 && resultCode == RESULT_OK && data != null) {
            //选择地址返回
            if (!data.hasExtra("SelectAddressMapBean")) {
                showMessage("选取地址异常");
                return;
            }
            MystoryAddStoryXxdz.setFocusableInTouchMode(true);
            MystoryAddStoryXxdz.setFocusable(true);
            MystoryAddStoryXxdz.requestFocus();
            SelectAddressMapBean selectAddressMapBean = (SelectAddressMapBean) data.getSerializableExtra("SelectAddressMapBean");
            MystoryAddStoryXxdz.setText(selectAddressMapBean.getDetileAddress());
            storeAddParmarBean.setLat(selectAddressMapBean.getLat());
            storeAddParmarBean.setLgt(selectAddressMapBean.getLgt());
            storeAddParmarBean.setAddressDetail(selectAddressMapBean.getDetileAddress());
        }
    }


    @Override
    public void setSelectImgType(StoryImageType selectImgType) {
        this.selectImgType = selectImgType;
    }

    @Override
    public void addStoreSuccess(String msg,MyStoryBean myStoryBean) {
        //"提交成功，请耐心等待审核，审核时间约3~5个工作日！"
        new AlertView("提示", msg, "我知道了", null, null, this, AlertView.Style.Alert, new AlertViewOnItemClickListener() {

            @Override
            public void onItemClick(Object o, int position) {
                Intent intent = new Intent();
                intent.putExtra("MyStoryBean", myStoryBean);
                intent.putExtra("type","addStore");
                setResult(RESULT_OK, intent);
                killMyself();
            }
        }).show();

    }

    @Override
    public void updateStoreSuccess(MyStoryBean myStoryBean) {
        AppUtil.midToast(this,"店铺修改成功");
        Intent intent = new Intent();
        intent.putExtra("MyStoryBean", myStoryBean);
        setResult(RESULT_OK, intent);
        killMyself();
    }

    @Override
    public TextView getMystoryAddStorySfz() {
        return MystoryAddStorySfz;
    }

    @Override
    public TextView getMystoryAddStoryYyzz() {
        return MystoryAddStoryYyzz;
    }


}
